package de.tum.in.eist.poll.client;

import com.google.gwt.event.dom.client.ChangeEvent;
import com.google.gwt.event.dom.client.ChangeHandler;
import com.google.gwt.event.logical.shared.CloseEvent;
import com.google.gwt.event.logical.shared.CloseHandler;
import com.google.gwt.user.client.Command;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.MenuItem;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.RootPanel;

public class MenuLectures{
	final ListBox listBox = new ListBox();
	public void showMenuLectures(){
		int numLectures = 5;
		for (int i = 1; i <= numLectures; i++){
			listBox.addItem("" + i);
		}
//		listBox.addItem("1");
//		listBox.addItem("2");
//		listBox.addItem("3");
		listBox.addChangeHandler(new ChangeHandler() {
			@Override
			public void onChange(ChangeEvent event) {
				int selectedIndex = listBox.getSelectedIndex();
				if (selectedIndex >= 0)
					Window.alert("Something got selected "
							+ listBox.getValue(selectedIndex));
				
			}
		});
		Label lblChooseYoureLecture = new Label("Choose you're lecture.");
		RootPanel.get().add(lblChooseYoureLecture, 34, 56);
		RootPanel.get().add(listBox,34,80);
	}
	
	public int getNumLecture(){
		int ind = listBox.getSelectedIndex();
		String s = listBox.getValue(ind);
		Integer x = Integer.parseInt(s);
		return x;
	}
		
	

	
//	public void showLectures(){
//		ListBox comboBox = new ListBox();
//		rootPanel.add(comboBox, 68, 179);
//		int numLectures = 5;
//		for (int i = 1; i <= numLectures; i++){
//			comboBox.addItem("" + i);
//		}
//
//		
//		
	

	
	
	
	
	
//	public void showLectures() {
//		// Make a command that we will execute from all leaves.
//		
//
//
//
//		// Make some sub-menus that we will cascade from the top menu.
//		// TO DO: newmLectures vom Server holen
//		final MenuBar fooMenu = new MenuBar(true);
//		for (int i = 1; i <= numLectures; i++){
//			Command cmd = new Command() {
//				public int ii;
//				public void execute() {
////					Window.alert("Item has been clicked!");
//				}
//				public void set(int i){
//					this.ii=i;
//				}
//			};
//			cmd.set(i);
//			fooMenu.addItem("" + i + "", cmd);
//		}
//		
//		MenuItem newItem = new MenuItem("New", (Command)null);
//		newItem.setCommand(new MyCommand(newItem));
//	
//		
//		fooMenu.addCloseHandler(new CloseHandler<PopupPanel>(){
//			@Override
//			public void onClose(CloseEvent<PopupPanel> event) {
//				Window.alert(fooMenu.getSelectedItem().getText());
//			}
//		});
//		
//
//		// Make a new menu bar, adding a few cascading menus to it.
//		MenuBar menu = new MenuBar();
//		menu.addItem("Select a lecture", fooMenu);
//
//
//		// Add it to the root panel.
//		RootPanel.get().add(menu,0,0);
//	}
}
